package pages

import (
	"github.com/GoAdminGroup/go-admin/context"
	"github.com/GoAdminGroup/go-admin/modules/config"
	"github.com/GoAdminGroup/go-admin/modules/db"
	"github.com/GoAdminGroup/go-admin/modules/language"
	aform "github.com/GoAdminGroup/go-admin/plugins/admin/modules/form"
	"github.com/GoAdminGroup/go-admin/template"
	"github.com/GoAdminGroup/go-admin/template/icon"
	"github.com/GoAdminGroup/go-admin/template/types"
	"github.com/GoAdminGroup/go-admin/template/types/form"
)

// GetMessagePublishForm 获取message发布
func GetMessagePublishForm(ctx *context.Context) (types.Panel, error) {

	components := template.Get(config.GetTheme())

	col1 := components.Col().GetContent()
	btn1 := components.Button().SetType("submit").
		SetContent(language.GetFromHtml("发布")).
		SetThemePrimary().
		SetOrientationRight().
		SetLoadingText(icon.Icon("fa-spinner fa-spin", 2) + `发布`).
		GetContent()
	btn2 := components.Button().SetType("reset").
		SetContent(language.GetFromHtml("Reset")).
		SetThemeWarning().
		SetOrientationLeft().
		GetContent()
	col2 := components.Col().SetSize(types.SizeMD(8)).
		SetContent(btn1 + btn2).GetContent()

	var panel = types.NewFormPanel()
	panel.AddField("topic", "topic", db.Varchar, form.Text).FieldMust()
	panel.AddField("payload", "payload", db.Varchar, form.TextArea)

	af := components.Form().
		SetContent(panel.FieldsWithDefaultValue()).SetHeader(panel.Header).
		SetPrefix(config.PrefixFixSlash()).
		SetUrl("/admin/form/message/publish").
		SetTitle("发送消息").
		SetHiddenFields(map[string]string{
			aform.PreviousKey: "/admin",
		}).
		SetOperationFooter(col1 + col2)

	return types.Panel{
		Content: components.Box().
			SetHeader(af.GetDefaultBoxHeader(true)).
			WithHeadBorder().
			SetBody(af.GetContent()).
			GetContent(),
		Title:       "发送消息",
		Callbacks:   panel.Callbacks,
		Description: "发送消息",
	}, nil
}
